package com.hulk.mq;

/**
 * 功能概要：消息产生,提交到队列中去 
 * @author CUIJIAJUN
 * @date   2017年1月6日
 * 
 */
import javax.annotation.Resource;  

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;  
import org.slf4j.LoggerFactory;  
import org.springframework.amqp.core.AmqpTemplate;  
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;  
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:MessageProducer_topic.xml"})
public class MessageProducer_topic {  
  
	@Resource
	private RabbitTemplate rabbitTemplate;
	
	@Test
    public void testRabbitMq() throws Exception {
        //第二个参数为路由key(routingKey)的值，当路由可以为test321.hello.test123时，两个消费队列都可以收到消息，当值为test321.hello.aaa时，只有绑定了test321.#的队列才可以收到消息，当值为ta1.hello.test123，只有绑定了*.*.test123的队列才可收到消息
        for(int i = 1; i <= 10; i++) {
            String str = "hello" + i;
        rabbitTemplate.send("leo.pay.topic.exchange", "test321.hello.test123", new Message(str.getBytes(), new MessageProperties()));
        System.out.println("SUCCESS="+i);
        }
    }
}  